
local ClassRef = app.mvc.createRenderClass(...)
function ClassRef.create()
    local sprite = ClassRef.extend(cc.CSLoader:createNode(Res.SettingLang))
	if sprite ~= nil then
		ccui.Helper:doLayout(sprite)
	end
	sprite:init()
	return sprite
end

function ClassRef:init()
    self.super.init(self)
   
    -- self:setBackGroundColorOpacity(0)

    local btn  = self._ui.Button_1
    self._btnHeight = btn:getContentSize().height
    self._btns = {btn }
    self._totalHeight = 0
end

---datalist = {{name="name1",id=1},{name="name2",id=2},{name="name3",id=3}}
---data = {dataList,pos,cb} 下拉条内容 位置 点击后的回调
function ClassRef:refresh()
    if not self._data then
        return
    end
    self:refreshBtns()
end

function ClassRef:refreshBtns()
    local size = self._ui.Panel:getContentSize()
    local height = #self._data * self._btnHeight
  
    self._ui.Panel:setContentSize(cc.size(size.width, height))
    self._ui.Panel:setAnchorPoint(0,0)
    local publisher = app:getPublisher()
    if publisher ~= Enums.Publisher.ema then
        self._ui.Panel:setAnchorPoint(0,1)
    end
    ccui.Helper:doLayout(self._ui.Panel)
    -- self._ui.bg:setContentSize(cc.size(size.width, height))
    -- self:setContentSize(cc.size(size.width, height))
    -- ccui.Helper:doLayout(self)

    for i,btn in ipairs(self._btns) do
        btn:setVisible(false)
    end

    for i,btnData in ipairs(self._data) do
        local btn = self._btns[i]
        if not btn then
            btn = self._btns[1]:clone()
            self._ui.Panel:addChild(btn)
            self._btns[#self._btns + 1] = btn
        end

        local posY = height - (i-1)*self._btnHeight - self._btnHeight * 0.5
        btn:setPositionY(posY)
        btn:setVisible(true)
        local text = btn:getChildByName("Text")
        text:setString(btnData.name)
        btn:addClickEventListener(function()
            print("=============>>>111")
            executeFunc(self._cb,btnData)
            self:hide()
        end)
    end
    
end

function ClassRef:setCallback(cb)
    self._cb = cb
end


-- function ClassRef:getPanelCo()
--     return self:getContentSize().height
-- end

-- function ClassRef:setPos(pos)
--     -- local halfWinHei = display.height/2
--     -- local halfWinWid = display.width/2
--     -- self._ui.Panel:setPosition(pos.x - halfWinWid, pos.y - halfWinHei - height * 0.5)
-- end



return ClassRef
